home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / September 96 / Re Saving weak refs. to other < prev    next >
Encoding:
Internet Message Format  |  1996-09-19  |  5.0 KB  |  [TEXT/ttxt]

  1. Subject:     Re: Saving weak refs. to other parts
  2. Sent:        9/18/96 10:11 AM
  3. Received:    9/18/96 10:11 AM
  4. From:        kswenson@keypress.com (Kirk Swenson)
  5. Reply-To:    ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List
  7.  
  8.  
  9. >We are making a suite of parts that can be connected to each other in
  10. >various ways by the users. The connections is used in a "run-time" mode of
  11. >the document to send messages between the parts (using extensions).
  12. >
  13. >I have been trying to figure out how to make this connetions persistent (the
  14. >users do not want to reconnect all the parts each time the document is
  15. >opened). I have found a solution that will save the references (using the
  16. >weak reference to the other parts storage unit) that work when I do a normal
  17. >save of the document.
  18. >
  19. >My problems start when I want this to function also during various cloning
  20. >operations (i.e. "Save a copy"). I am using ODF for this work, but I think
  21. >this is partly an ODF and partly an OD problem.
  22.  
  23. We faced the same problem a while back, and had to work through the same
  24. issues.  I had intended to send a note to the list about it but got
  25. sidetracked.  Your message reminded me, so here it is.
  26.  
  27. >1. ODFs handling of CloneInto for non-embedding parts simply externalizes
  28. >the content, and though there are parameters for cloning info it does not
  29. >use them. Of course, I can override FW_Parts CloneInto and make a sollution
  30. >like for embedding parts. But is there any specific reason why the default
  31. >FW_Part behavior is different from the embedding parts?
  32.  
  33. I use the FW_CEmbeddingPart::CloneInto override for all of my parts,
  34. embedding or not.  Suggestion to the ODF team: The clone information is
  35. useful for other reasons than embedding.  I would like to see it forwarded
  36. to all parts, not just non-embedding parts.  In other words,
  37. FW_CEmbeddingPart::CloneInto could be moved to FW_CPart, and then all parts
  38. would have access to the clone info.
  39.  
  40. >2. This one is my -real- problem. During a cloning operation, I suppose that
  41. >the right thing to do with my connected parts, is to use WeakClone. The
  42. >documentation tells me that WeakClone will return an ID that I can use to
  43. >get a weak reference -after- the cloning operation is finished; that is
  44. >after EndClone if I understand it right. If my part started the cloning
  45. >operation, this would be OK. But what happens in case of "Save as..." or if
  46. >there is clipboard operation that invloves my part, but that was made from a
  47. >part my part is embedded in? Possibly I have overlooked some detail here,
  48. >but what I seem to miss is some sort of "PostClone" operation that lets my
  49. >part check if the ID from WeakClone is valid after the cloning, and saves
  50. >either the weak reference or a "NULL-tag" of some sort together with my
  51. >"normal" content data.
  52.  
  53. I have posted code at the end of this message that seems to be working for
  54. me.  As you suggested, the crux of the matter is using WeakClone when
  55. cloning.  Suggestion to the ODF team: FW_CCloneInfo has methods for cloning
  56. strong references.  It seems like an appropriate place to add methods for
  57. cloning weak references as well.  The code posted below would be simplified
  58. substantially with the addition of such a method, and it would be one less
  59. wheel for others to reinvent.
  60.  
  61. Kirk Swenson
  62. Senior Software Engineer
  63. Key Curriculum Press
  64. kswenson@keypress.com
  65.  
  66. ------------------------------------------------------------------------------
  67. Here's the code.  Note that it doesn't seem to be possible to write out a
  68. null reference, so the presence or absence of a reference must be indicated
  69. separately.
  70.  
  71. void
  72. KCP_CODPersistentReference::
  73. WriteWeakReference(
  74.     Environment*            ev,
  75.     FW_CWritableStream&     ioWriteStream,
  76.     ODStorageUnit*          ioDestSU,
  77.     FW_CCloneInfo*          iCloneInfo) const
  78. {
  79.     FW_ASSERT( mPersistentID != kODNULLID);
  80.  
  81.     // If we are not cloning, we can just write out a reference to the
  82.     // persistent ID we already have.
  83.     ODID                    tIDToWrite = mPersistentID;
  84.     ODStorageUnitRef        tWeakReference;
  85.  
  86.     // If we are cloning, then we need to translate our part ID into
  87.     // the correct ID for the newly cloned storage unit.
  88.     if( iCloneInfo != nil) {
  89.  
  90.         ODDraft*            tFromDraft = iCloneInfo->GetFromDraft( ev);
  91.         FW_ASSERT( tFromDraft != nil);
  92.  
  93.         FW_CFrame*          tScopeFrame = iCloneInfo->GetScopeFrame( ev);
  94.         FW_ASSERT( tScopeFrame != nil);
  95.  
  96.         ODID                tScopeFrameID = tScopeFrame->GetID( ev);
  97.  
  98.         tIDToWrite = tFromDraft->WeakClone(
  99.                                     ev,
  100.                                     iCloneInfo->GetDraftKey( ev),
  101.                                     tIDToWrite,
  102.                                     kODNULLID,
  103.                                     tScopeFrameID);
  104.  
  105.         FW_ASSERT( tIDToWrite != kODNULLID);
  106.     }
  107.  
  108.     // Convert the ID to a weak storage unit reference.
  109.     ioDestSU->GetWeakStorageUnitRef( ev, tIDToWrite, tWeakReference);
  110.  
  111.     // Write out the weak storage unit reference
  112.     ioWriteStream.Write( &tWeakReference, sizeof( tWeakReference));
  113. }